﻿using DocumentFormat.OpenXml.Office2010.Excel;
using ERP.ERPSystem.ProductionSystem;
using ERP.ERPSystem.ProductionSystem.Dto;
using ERP.ERPSystem.RBAC.Dto;
using ERP.Team.ProductionSystem;
using ERP.Team.RBAC;
using Humanizer;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace ERP.Web.Controllers.ProductionSystem
{
    /// <summary>
    /// 生产系统-生产报工-xzc
    /// </summary>
    public class ProductionReportController : Controller
    {
        private readonly IProduceWorkServices _produceWorkServices;

        public ProductionReportController(IProduceWorkServices produceWorkServices)
        {
            this._produceWorkServices = produceWorkServices;
        }

        /// <summary>
        /// 生产报工视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ProductionReportView()
        {
            return View();
        }
        /// <summary>
        /// 查询生产报工
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetProductionReportingMain(GetProductionReportingMainDto getproductioreportingmaindto)
        {
            var data = await _produceWorkServices.GetProductionReportingMain(getproductioreportingmaindto);
            return Json(new { code = 0, msg = "", data = data });
        }
        /// <summary>
        /// 新增生产报工视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ProductionReportAddView()
        {
            return View();
        }
        /// <summary>
        /// 新增生产报工
        /// </summary>
        /// <param name="productionreportingmaindto"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<int> AddProductionReportingMain(ProductionReportingMainDto productionreportingmaindto)
        {
            var i = await _produceWorkServices.AddProductionReportingMain(productionreportingmaindto);
            return i;
        }
        /// <summary>
        /// 删除生产报工
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]  
        public async Task DeleteProductionReportingMain(int id)
        {
            await _produceWorkServices.DeleteProductionReportingMain(id);
        }
        /// <summary>
        /// 批量删除生产报工
        /// </summary>
        /// <param name="ids">要删除的ID数组</param>
        /// <returns>删除成功的数量</returns>
        [HttpPost]
        public async Task<int> BatchDeleteProductionReportingMain([FromBody] List<int> ids)
        {
            if (ids == null || ids.Count == 0)
            {
                return 0;
            }
            return await _produceWorkServices.BatchDeleteProductionReportingMain(ids.ToArray());
        }
        /// <summary>
        /// 反填生产报工视图
        /// </summary>
        /// <returns></returns>
        public IActionResult FindProductionReportAddView()
        {
            return View();
        }
        /// <summary>
        /// 通过主键id查询到相关的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ProductionReportingMain> FindProductionWorkOrderMain(int id)
        {
            return await _produceWorkServices.FindProductionWorkOrderMain(id);
        }
        /// <summary>
        /// 更新生产报工视图
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateProductionReportAddView()
        {
            return View();
        }
        /// <summary>
        /// 更新生产报工
        /// </summary>
        /// <param name="productionreportingmaindto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateProductionReportingMain(ProductionReportingMainDto productionreportingmaindto)
        {
            var i = await _produceWorkServices.UpdateProductionReportingMain(productionreportingmaindto);
            return i;
        }
        /// <summary>
        /// 生产工单视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ProductionWorkOrderMainView()
        {
            return View();
        }
        /// <summary>
        /// 查询工单的信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<ProductionWorkOrderMain>> GetProductionWorkOrderMain(GetProductionWorkOrderMainDto getproductionworkordermaindto)
        {
            return await _produceWorkServices.GetProductionWorkOrderMain(getproductionworkordermaindto);
        }
        /// <summary>
        /// 生产任务视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ProductionTaskView()
        {
            return View();
        }
        /// <summary>
        /// 查询生产任务的信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<ProductionTask>> GetProductionTask(string? processBelongs, string? workstationCode, string? taskNumber)
        {
            return await _produceWorkServices.GetProductionTask(processBelongs, workstationCode, taskNumber);
        }
        /// <summary>
        /// 报工人视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ReportWorkerView()
        {
            return View();
        }
        /// <summary>
        /// 审核人视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ReviewersView()
        {
            return View();
        }
        /// <summary>
        /// 查询部门数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<DepartmentModel>> GetDepartment()
        {
            var i = await _produceWorkServices.GetDepartment();
            return i;
        }
        /// <summary>
        /// 点击部门查询相对应的用户
        /// </summary>
        /// <param name="departmentid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<UserModel>> GetUser(int departmentid)
        {
            var i = await _produceWorkServices.GetUser(departmentid);
            return i;
        }
    }
}
